//  Copyright 2009 David Ekholm, Jalbum AB
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.package net.jalbum.jprint;
package net.jalbum.jprint;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import se.datadosen.jalbum.JAlbumPlugin;
import se.datadosen.jalbum.PluginContext;

/**
 * Prints selected JAlbum images onto a local printer
 * @author david
 */
public class JPrintSelectedPlugin  implements JAlbumPlugin {

    private static final ImageIcon smallIcon = new ImageIcon(JPrintSelectedPlugin.class.getResource("images/printer16.png"));

    private JPrintDialog dialog;
    private PluginContext context;

    private final Action openDialogAction = new AbstractAction("Print selected...") {
        {
            putValue(Action.SMALL_ICON, smallIcon);
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
            putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P);
//            putValue(Action.SHORT_DESCRIPTION,"Short description");
        }

        public void actionPerformed(ActionEvent e) {
            if (dialog == null) {
                dialog = new JPrintDialog(context);
                dialog.setLocationRelativeTo(context.getJAlbumContext().getFrame());
            }
            dialog.setVisible(true);
        }
    };

    public void init(PluginContext context) {
        this.context = context;
        context.addContextMenuItem(new JMenuItem(openDialogAction));
//        context.addToolBarAction(openPrintSettingsAction, true);
    }

    public boolean onExit() {
        return true;
        // Todo, ask if user wants to finnish print job
    }
}
